home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 11: TSX-11 / Linux Cubed Series 11 - TSX-11 Vol 1.iso / sbin / bootutil.1 / bootutil / bootutils / mount / swapon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-01  |  1.2 KB  |  72 lines

  1. /* swapon(8)/swapoff(8) for Linux 0.97.3.
  2.    $Header: /usr/src/mount/RCS/swapon.c,v 1.1 1992/09/06 13:30:53 root Exp root $ */
  3.  
  4. #include "sundries.h"
  5.  
  6. static char const * progname;
  7.  
  8. static volatile void
  9. usage (void)
  10. {
  11.   fprintf (stderr, "Usage: %s [-a] [special_file ...]\n", progname);
  12.   exit (2);
  13. }
  14.  
  15. static int
  16. swap (const char *special)
  17. {
  18.   int status;
  19.  
  20.   if (streq (progname, "swapon"))
  21.     status = swapon (special);
  22.   else
  23.     status = swapoff (special);
  24.  
  25.   if (status < 0)
  26.     fprintf (stderr, "%s: %s: %s\n", progname, special, strerror (errno));
  27.  
  28.   return status;
  29. }
  30.  
  31. int
  32. main(int argc, char **argv)
  33. {
  34.   struct fstab *fstab;
  35.   int status;
  36.   int opt;
  37.   int all = 0;
  38.  
  39.   if (strrchr (argv[0], '/') != NULL)
  40.     progname = strrchr (argv[0], '/') + 1;
  41.   else
  42.     progname = argv[0];
  43.  
  44.   while ((opt = getopt(argc, argv, "a")) != EOF)
  45.     switch(opt)
  46.       {
  47.       case 'a':    ++all; break;
  48.       default:  usage ();
  49.       }
  50.  
  51.   argv += optind;
  52.  
  53.   status = 0;
  54.  
  55.   if (all)
  56.     {
  57.       while ((fstab = getfsent()) != NULL)
  58.     if (streq (fstab->fs_type, FSTAB_SW))
  59.       status |= swap (fstab->fs_spec);
  60.     }
  61.   else if (*argv == NULL)
  62.     {
  63.       usage ();
  64.     }
  65.   else
  66.     {
  67.       while (*argv != NULL)
  68.     status |= swap (*argv++);
  69.     }
  70.   return status;
  71. }
  72.